package com.agriculture.data_demo.repository;

import com.agriculture.data_demo.entity.sys.BroilerDailyEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author morningbear
 * @date 20.10.7
 */
@Repository
public interface BroilerDailyRepository extends JpaRepository<BroilerDailyEntity, Integer> {

    @Query(value = "select * from broiler_daily", nativeQuery = true)
    Page<BroilerDailyEntity> findAll(PageRequest of);

    /**
     *
     * @param of 请求分页对象
     * @return 查询饮食和饮水非空的记录
     */
    @Query(value = "select * from broiler_daily where eatFood and drink is not null ", nativeQuery = true)
    Page<BroilerDailyEntity> findAllNull(PageRequest of);

    /**
     *
     * @param fence 鸡舍
     * @return 根据鸡舍查询
     */
    Page<BroilerDailyEntity> findByFence(String fence, Pageable pageable);

    /**
     *
     * @param startDate 查询起始日期
     * @param endDate 查询结束日期
     * @return 查询时间段中的肉鸡生产周期数据
     */
    @Query(value = "select * from broiler_daily where broiler_daily.create_at between ?1 and ?2", nativeQuery = true)
    Page<BroilerDailyEntity> findBroilerDailyEntitiesByDate(Date startDate, Date endDate, Pageable pageable);
}
